public static NSArray overdueRentalsWithEditingContext(In Objective-C:
EOEditingContext ec)
{
NSGregorianDate today = new NSGregorianDate();
EOQualifier qualifer = new EOKeyValueQualifier(
"dueDate",
EOQualifier.QualifierOperatorLessThan,
today);
EOFetchSpecification fetchSpec = new EOFetchSpecification(
@"Rental",
qualifer,
null);
return ec.objectsWithFetchSpecification(fetchSpec);
}
+ (NSArray *)You would then invoke the method as follows:
overdueRentalsWithEditingContext:(EOEditingContext *)ec
{
NSCalendarDate *today = [NSCalendarDate calendarDate];
EOQualifier *qualifer =
[EOQualifier qualifierWithQualifierFormat:
@"dueDate < %@",
today];
EOFetchSpecification *fetchSpec =
[EOFetchSpecification
fetchSpecificationWithEntityName:@"Rental"
qualifier:qualifer sortOrderings:nil];
return [ec objectsWithFetchSpecification:fetchSpec];
}
rentalArray = Rental.overdueRentalsWithEditingContext(ec);In Objective-C:
rentalArray = [Rental overdueRentalsWithEditingContext:ec];Note that overdueRentalsWithEditingContext takes an EOEditingContext as an argument. This is because enterprise objects are fetched into a particular EOEditingContext. An EOEditingContext establishes a single, internally consistent "object view" of the database, and an enterprise object in one editing context shouldn't have references to enterprise objects in another one. Consequently, methods that fetch enterprise objects must fetch them using the correct EOEditingContext.
Because a class object is global, its static methods (class methods in Objective-C) can be invoked from anywhere in an application. Thus, a class method that returns enterprise objects fetched from the database needs to receive the correct EOEditingContext as an argument.
Note: While the Rental class in this example closely resembles the Rental class for the sample Rentals database, dueDate has been added here to simplify the qualifier for fetching overdue rentals. The Rental class for the sample Rentals database doesn't have a dueDate attribute.
Table of Contents
Next Section